package com.youku.adSDK.view.components
{
   import flash.display.Sprite;
   import flash.text.TextField;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   import flash.text.TextFormatAlign;
   import com.youku.utils.AssetUtil;
   import flash.display.MovieClip;
   import flash.events.MouseEvent;
   import com.youku.adSDK.view.events.VideoADEvent;
   
   public class ADCountdown extends Sprite
   {
      
      public function ADCountdown() {
         super();
      }
      
      private var _timeLayer:Sprite;
      
      private var _volumeLayer:Sprite;
      
      private var _passLayer:Sprite;
      
      private var _timeTf:TextField;
      
      private var _muteOn:Sprite;
      
      private var _muteOff:Sprite;
      
      private var _textFormat:TextFormat;
      
      private var _timeTextFormat:TextFormat;
      
      private var _muteTextFormat:TextFormat;
      
      private var _span:Number = 1;
      
      private var _passTf:TextField;
      
      public function init() : void {
         this.createItems();
         this.addEvents();
      }
      
      private function createItems() : void {
         this._textFormat = new TextFormat();
         this._textFormat.font = YaheiFontManager.MICROSOFT_YAHEI;
         this._textFormat.size = 12;
         this._textFormat.color = 13421772;
         this._muteTextFormat = new TextFormat();
         this._muteTextFormat.font = YaheiFontManager.MICROSOFT_YAHEI;
         this._muteTextFormat.size = 12;
         this._muteTextFormat.color = 0;
         this._timeTextFormat = new TextFormat();
         this._timeTextFormat.align = TextFormatAlign.CENTER;
         this._timeTextFormat.font = YaheiFontManager.MICROSOFT_YAHEI;
         this._timeTextFormat.size = 14;
         this._timeTextFormat.color = 14171686;
         this._timeLayer = new Sprite();
         this.addChild(this._timeLayer);
         var _loc1_:MovieClip = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         _loc1_.width = 100;
         _loc1_.height = 26;
         this._timeLayer.addChild(_loc1_);
         var _loc2_:TextField = new TextField();
         _loc2_.defaultTextFormat = this._textFormat;
         _loc2_.selectable = false;
         _loc2_.width = 54;
         _loc2_.height = 20;
         _loc2_.x = 6;
         _loc2_.y = 2;
         _loc2_.text = "广告剩余";
         this._timeLayer.addChild(_loc2_);
         var _loc3_:TextField = new TextField();
         _loc3_.defaultTextFormat = this._textFormat;
         _loc3_.selectable = false;
         _loc3_.width = 20;
         _loc3_.height = _loc2_.height;
         _loc3_.x = 78;
         _loc3_.y = _loc2_.y;
         _loc3_.text = "秒";
         this._timeLayer.addChild(_loc3_);
         this._timeTf = new TextField();
         this._timeTf.defaultTextFormat = this._timeTextFormat;
         this._timeTf.selectable = false;
         this._timeTf.width = 25;
         this._timeTf.text = "";
         this._timeTf.x = 56;
         this._timeTf.y = 1;
         this._timeLayer.addChild(this._timeTf);
         this._volumeLayer = new Sprite();
         this._volumeLayer.x = this._timeLayer.width + this._span;
         this._volumeLayer.buttonMode = true;
         this._volumeLayer.useHandCursor = true;
         this.addChild(this._volumeLayer);
         this._muteOff = new Sprite();
         this._volumeLayer.addChild(this._muteOff);
         var _loc4_:MovieClip = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         _loc4_.width = 40;
         _loc4_.height = _loc1_.height;
         this._muteOff.addChild(_loc4_);
         var _loc5_:TextField = new TextField();
         _loc5_.defaultTextFormat = this._textFormat;
         _loc5_.selectable = false;
         _loc5_.width = 28;
         _loc5_.height = _loc2_.height;
         _loc5_.x = 6;
         _loc5_.y = _loc2_.y;
         _loc5_.text = "静音";
         this._muteOff.addChild(_loc5_);
         var _loc6_:Sprite = new Sprite();
         _loc6_.graphics.beginFill(0,0);
         _loc6_.graphics.drawRect(0,0,_loc4_.width,_loc4_.height);
         this._muteOff.addChild(_loc6_);
         this._muteOn = new Sprite();
         this._volumeLayer.addChild(this._muteOn);
         var _loc7_:Sprite = new Sprite();
         _loc7_.graphics.beginFill(436193);
         _loc7_.graphics.drawRect(0,0,_loc4_.width,_loc4_.height);
         _loc7_.graphics.endFill();
         this._muteOn.addChild(_loc7_);
         var _loc8_:TextField = new TextField();
         _loc8_.defaultTextFormat = this._muteTextFormat;
         _loc8_.selectable = false;
         _loc8_.width = _loc5_.width;
         _loc8_.height = _loc5_.height;
         _loc8_.x = _loc5_.x;
         _loc8_.y = _loc5_.y;
         _loc8_.text = _loc5_.text;
         this._muteOn.addChild(_loc8_);
         this._muteOn.visible = false;
         var _loc9_:Sprite = new Sprite();
         _loc9_.graphics.beginFill(0,0);
         _loc9_.graphics.drawRect(0,0,_loc7_.width,_loc7_.height);
         this._muteOn.addChild(_loc9_);
         this._passLayer = new Sprite();
         this._passLayer.buttonMode = true;
         this._passLayer.useHandCursor = true;
         this._passLayer.x = this._timeLayer.width + this._span + this._volumeLayer.width + this._span;
         this.addChild(this._passLayer);
         var _loc10_:MovieClip = AssetUtil.getAsset("V4_panel_bg") as MovieClip;
         _loc10_.width = 64;
         _loc10_.height = _loc1_.height;
         this._passLayer.addChild(_loc10_);
         this._passTf = new TextField();
         this._passTf.defaultTextFormat = this._textFormat;
         this._passTf.selectable = false;
         this._passTf.width = 52;
         this._passTf.height = _loc2_.height;
         this._passTf.x = 6;
         this._passTf.y = _loc2_.y;
         this._passTf.text = "跳过广告";
         this._passLayer.addChild(this._passTf);
         var _loc11_:Sprite = new Sprite();
         _loc11_.graphics.beginFill(0,0);
         _loc11_.graphics.drawRect(0,0,_loc10_.width,_loc10_.height);
         this._passLayer.addChild(_loc11_);
      }
      
      private function addEvents() : void {
         this._muteOff.addEventListener(MouseEvent.CLICK,this.onMuteOffClick);
         this._muteOn.addEventListener(MouseEvent.CLICK,this.onMuteOnClick);
         this._passLayer.addEventListener(MouseEvent.CLICK,this.onPassClick);
      }
      
      private function onPassClick(param1:MouseEvent) : void {
         this.dispatchEvent(new VideoADEvent(VideoADEvent.AD_PASS));
      }
      
      private function onMuteOffClick(param1:MouseEvent) : void {
         this._muteOn.visible = true;
         this._muteOff.visible = false;
         this.sendEvent(true);
      }
      
      private function onMuteOnClick(param1:MouseEvent) : void {
         this._muteOn.visible = false;
         this._muteOff.visible = true;
         this.sendEvent(false);
      }
      
      private function sendEvent(param1:Boolean) : void {
         var _loc2_:VideoADEvent = new VideoADEvent(VideoADEvent.AD_MUTE);
         _loc2_.isMute = param1;
         this.dispatchEvent(_loc2_);
      }
      
      public function showTime(param1:String) : void {
         this._timeTf.text = param1;
      }
      
      public function showPass() : void {
         this._passLayer.visible = true;
      }
      
      public function hidePass() : void {
         this._passLayer.visible = false;
      }
      
      public function setMute(param1:Boolean) : void {
         this._muteOff.visible = !param1;
         this._muteOn.visible = param1;
      }
      
      override public function get width() : Number {
         var _loc1_:Number = this._timeLayer.width + this._volumeLayer.width + this._span;
         _loc1_ = _loc1_ + (this._passLayer.visible?this._passLayer.width + this._span:0);
         return _loc1_;
      }
      
      public function get timeVisible() : Boolean {
         return this._timeLayer.visible;
      }
      
      public function set timeVisible(param1:Boolean) : void {
         this._timeLayer.visible = param1;
      }
      
      public function setPassText(param1:String) : void {
         this._passTf.text = param1;
      }
   }
}
